#pragma once
#include "VideoDecoder.h"
class PSDecoder :
	public VideoDecoder
{
public:
	PSDecoder(void);
	~PSDecoder(void);

	void startRecvThread();
	void startDecodeThread();
	bool recvThreadRunning;

protected:
	bool findVideoPES(unsigned char* currentPESFrame, unsigned char* PSBufferFrame,  int& bufferLength, unsigned char* splitter,int splitterLength, int& bodyLength);
	int find(unsigned char* buffer,  int bufferLength, unsigned char* splitter,int splitterLength);

	char* recvBuf;

	int lostPacket;
	int RTPHeaderSize;

	unsigned char* PSBuffer;
	unsigned char* PSBufferFrame;

	unsigned char* currentPESFrame;
	unsigned char* PESBufferFrame;
	int bufferSize;
	unsigned char* PESFrame;

	int PSBufferOffset;
	int PESFrameOffset;
	unsigned char* PESsplitter;
	unsigned char* H264splitter;

	uint64_t timestamp;

	AVCodec *codec;
	AVCodecContext *c;

	AVPacket avpkt;
};

